feat(transport): Add EnvelopePrinterTransport for debug logging#6181
feat(transport): Add EnvelopePrinterTransport for debug logging#6181ericapisani merged 14 commits intomasterfrom
Conversation
Add a decorator transport that logs envelope contents via the SDK debug logger before forwarding to the inner transport. Activated by setting SENTRY_PRINT_ENVELOPES=1|true|yes. Includes tests for delegation, logging behavior, make_transport integration, and strict env var parsing. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Codecov Results 📊✅ 13 passed | Total: 13 | Pass Rate: 100% | Execution Time: 6.90s 📊 Comparison with Base Branch
✨ No test changes detected All tests are passing successfully. ❌ Patch coverage is 40.68%. Project has 15136 uncovered lines. Files with missing lines (1)
Coverage diff@@ Coverage Diff @@
## main #PR +/-##
==========================================
+ Coverage 31.29% 31.30% +0.01%
==========================================
Files 190 190 —
Lines 21985 22032 +47
Branches 7394 7400 +6
==========================================
+ Hits 6880 6896 +16
- Misses 15105 15136 +31
- Partials 581 583 +2Generated by Codecov Action |
|
bugbot run |
|
@sentry review |
…sport coverage - Override __class__ to delegate to inner transport so isinstance checks (e.g. AsyncHttpTransport) remain transparent - Add __getattr__ fallback for attributes not explicitly defined - Return values from flush() and kill() so async tasks propagate - Wrap transport in all make_transport paths (pre-instantiated, callable) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
bugbot run |
|
@sentry review |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit f050b85. Configure here.
…ry/sentry-python into envelope-printer-transport-zcgvd
There was a problem hiding this comment.
The snippet below should probably work without crashing, since that's the canonical way to provide an alternative transport.
Maybe we create a transport which only prints to the terminal without wrapping another transport?
import sentry_sdk
from sentry_sdk.transport import _EnvelopePrinterTransport
sentry_sdk.init(
dsn="...",
transport=_EnvelopePrinterTransport,
)|
@alexander-alderman-webb Given this transport is for debugging purposes on our end, I opted for the wrapping approach so that we don't need to change how we've configured the SDK, which was intended to include specific transports we may be leveraging for our use case. Is there something in particular that you're concerned about with this approach? |
|
My main concern is that we need to set I agree that wrapping would be the nicest approach but I don't think our current abstractions were designed for this kind of wrapping 😞. |
| ) | ||
| logger.debug("--- End Envelope ---") | ||
| except Exception: | ||
| pass |
There was a problem hiding this comment.
Silent exception swallowing hides debug tool failures
Low Severity
The bare except Exception: pass in capture_envelope silently swallows all errors during envelope printing without any feedback. Since this is specifically a debugging tool activated by SENTRY_PRINT_ENVELOPES=1, silently failing defeats the tool's purpose — a developer who enables it and sees no output would have no way to know why. The SDK's own capture_internal_exceptions pattern logs exceptions rather than discarding them entirely.
Reviewed by Cursor Bugbot for commit 8d69e7b. Configure here.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
There are 3 total unresolved issues (including 2 from previous reviews).
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 5205418. Configure here.
Revert "Do not require a DSN to be set to use the envelope pretty print transport" This reverts commit 5205418.
…move the need to set the debug property in the sentry client when the env var controlling this is set
alexander-alderman-webb
left a comment
There was a problem hiding this comment.
Looks good! I ran a simple example and can confirm that envelopes appear in the terminal.
Thanks for making the changes!
| isolation_scope, | ||
| get_isolation_scope, | ||
| Hub, | ||
| isolation_scope, |
There was a problem hiding this comment.
Probably best to remove the changes in test_transport.py since we're not adding any tests. Although it's only import ordering so this is a nitpick.


Adds
EnvelopePrinterTransport, a decorator transport that wraps the real transport and pretty-prints each envelope's headers and item payloads to the SDK debug logger before forwarding the envelope.Enabled via
SENTRY_PRINT_ENVELOPES=1(also acceptstrue/yes). When unset or falsy, no wrapping occurs and there's no runtime cost. Useful for local debugging without having to run a local Sentry instance or intercept network traffic.Fixes PY-2398
Fixes #6183